public partial class CalculatorForm : Form
{
    private double _value = 0;
    private string _operation = "";
    private bool _operationPressed = false;

    public CalculatorForm()
    {
        InitializeComponent();
    }

    private void button_Click(object sender, EventArgs e)
    {
        if ((txtDisplay.Text == "0") || _operationPressed)
            txtDisplay.Clear();

        _operationPressed = false;
        Button button = (Button)sender;
        txtDisplay.Text = txtDisplay.Text + button.Text;
    }

    private void operator_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        _operation = button.Text;
        _value = double.Parse(txtDisplay.Text);
        _operationPressed = true;
    }

    private void btnEquals_Click(object sender, EventArgs e)
    {
        switch (_operation)
        {
            case "+":
                txtDisplay.Text = (_value + double.Parse(txtDisplay.Text)).ToString();
                break;
            case "-":
                txtDisplay.Text = (_value - double.Parse(txtDisplay.Text)).ToString();
                break;
            case "*":
                txtDisplay.Text = (_value * double.Parse(txtDisplay.Text)).ToString();
                break;
            case "/":
                txtDisplay.Text = (_value / double.Parse(txtDisplay.Text)).ToString();
                break;
            default:
                break;
        }
        _operation = "";
    }

    private void btnClear_Click(object sender, EventArgs e)
    {
        txtDisplay.Text = "0";
        _value = 0;
    }
}